import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:tot_android_flutter/utils/utils_ext.dart';


import '../../eneity/article_entity.dart';

typedef OnCollectCallback = void Function(ArticleDataDatas article);
typedef OnClickCallback = void Function(ArticleDataDatas article);

class AritcleItemWidget extends StatelessWidget {
  final ArticleDataDatas article;
  final OnClickCallback onClickCallback;
  final OnCollectCallback? onCollectTap;

  const AritcleItemWidget({
    Key? key,
    required this.article,
    required this.onClickCallback,
    this.onCollectTap,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    StringBuffer _tags = StringBuffer(article.superChapterName ?? "");
    if (_tags.isNotEmpty &&
        article.chapterName != null &&
        article.chapterName!.isNotEmpty) {
      _tags.write("·");
    }
    _tags.write(article.chapterName ?? "");

    String _author = article.author;
    if (article.author.isEmpty) {
      _author = article.shareUser;
    }

    return Container(
      margin: EdgeInsets.fromLTRB(16.w, 4.w, 16.w, 4.w),
      child: Card(
          elevation: 5,
          color: Colors.white,
          shape:
              BeveledRectangleBorder(borderRadius: BorderRadius.circular(15.w)),
          child: Container(
              padding: EdgeInsets.all(16.w),
              child: GestureDetector(
                onTap: () {
                  onClickCallback(article);
                },
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      // crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text(_author,style: TextStyle(fontSize: 14.w),),
                        Text(article.niceDate,style: TextStyle(fontSize: 14.w),),
                      ],
                    ),
                    SizedBox(height: 10.w),
                    Html(
                      data: article.title,
                      style: {
                        "html": Style(
                            margin: Margins.zero,
                            maxLines: 2,
                            textOverflow: TextOverflow.ellipsis,
                            fontSize: FontSize(16.w),
                            padding: HtmlPaddings.zero,
                            alignment: Alignment.topLeft),
                        "body": Style(
                            margin: Margins.zero,
                            maxLines: 2,
                            textOverflow: TextOverflow.ellipsis,
                            fontSize: FontSize(16.w),
                            padding: HtmlPaddings.zero,
                            alignment: Alignment.topLeft)
                      },
                    ),
                    SizedBox(height: 10.w),
                    Row(
                      children: [
                        Expanded(
                          child: Text(
                            _tags.toString(),
                            style: TextStyle(fontSize: 15.w),
                            overflow: TextOverflow.ellipsis,
                            softWrap: false, // 禁止换行
                          ),
                        ),
                        GestureDetector(
                            onTap: () {
                              onCollectTap?.call(article);
                            },
                            child: Container(
                              width: 28.w,
                              height: 28.w,
                              child: Image.asset(article.collect
                                  ? "assets/image/icon_collect.png"
                                  : "assets/image/icon_uncollect.png"),
                            ))
                      ],
                    ),
                  ],
                ),
              ))),
    );
  }

  String decodeHtmlEntities(String input) {
    return Uri.decodeComponent(input);
  }
}

mixin w {
  
}
